/**
 * Unicode表示法
 */

// {
//     console.log('a', `\u0061`);
//     console.log('s', `\u20BB7`);
//     console.log('s', `\u{20BB7}`);
// }


// {
//     let s = '𠮷';
//     console.log('length', s.length);
//     console.log('0', s.charAt(0));
//     console.log('1', s.charAt(1));
//     console.log('at0', s.charCodeAt(0));
//     console.log('at1', s.charCodeAt(1));

//     let s1 = '𠮷a';
//     console.log('length', s1.length);
//     console.log('code0', s1.codePointAt(0));
//     console.log('code0', s1.codePointAt(0).toString(16));
//     console.log('code1', s1.codePointAt(1));
//     console.log('code2', s1.codePointAt(2));
// }

// {
//     console.log(String.fromCharCode("0x20bb7"));
//     console.log(String.fromCodePoint("0x20bb7"));
// }

console.log("----------------------------------------")

/**
 * 字符串-遍历接口
 */

{
    let str = '\u{20bb7}abc';
    for (let i = 0; i < str.length; i++) {
        console.log('es5', str[i]);
    }

    // ES6 中 "{20bb7}" 当成一个字符串
    for (let code of str) {
        console.log('es6', code);
    }
}

console.log("----------------------------------------")

/**
 * 模板字符串
 */
{
    let user = {
        name: 'list',
        info: 'hello world'
    };
    console.log(`i am ${user.name},${user.info}`);


    function abc(s, v1, v2) {
        console.log(s, v1, v2);
        return s + v1 + v2
    }
    abc`i am ${user.name},${user.info}` // 输出:  ["i am ", ",", "", raw: Array(3)] "list" "hello world"
}
console.log("----------------------------------------")

/**
 * ES6 新增方法
 */


{
    let str = "string";
    console.log('includes', str.includes("c"));
    console.log('startsWith(是否以xxx开头)', str.startsWith('str'));
    console.log('endsWith(是否以xxx结尾)', str.endsWith('ng'));

    console.log("repeat, 重复X次", str.repeat(2));

    console.log("开头添加", '1'.padStart(2, '0'));
    console.log("结尾添加", '1'.padEnd(2, '0'));

    console.log("转译", String.raw`Hi\n${1 + 2}`);
    console.log("不转译",`Hi\n${1 + 2}`);
}